package net.csdn.www;

public class Test27 {

	/**
	 * 刘柱栋    2013-3-28
	 * @param args
	 */
	public static void main(String[] args) {
		Printer printer = new Printer();
		
		new Thread(new PrintNumber(printer)).start();
		new Thread(new PrintChar(printer)).start();
	}

}

class Printer {
	private static int index = 1;
	public synchronized void printNumber(int i){
		while(index % 3 == 0){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		index++;
		System.out.print(i);
		notify();
	}
	
	public synchronized void printChar(char c){
		while(index % 3 != 0){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		index++;
		System.out.print(c);
		notify();
	}
}

class PrintNumber implements Runnable{
	private Printer print;
	public PrintNumber(){ }
	public PrintNumber(Printer print){
		this.print = print;
	}
	@Override
	public void run() {
		for(int i = 1 ; i <= 52 ; i++ ){
			print.printNumber(i);
		}
	}
	
}

class PrintChar implements Runnable{
	private Printer print;
	public PrintChar(){ }
	public PrintChar(Printer print){
		this.print = print;
	}
	@Override
	public void run() {
		for(char i ='A' ; i <= 'Z' ; i++ ){
			print.printChar(i);
		}
	}
	
}
